// 云函数入口文件
const cloud = require('wx-server-sdk');

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV,
});

// 获取云数据库用例
const db = cloud.database();

// 云函数入口函数
exports.main = async (event, context) => {
  const pagesize = event.pagesize;
  const pagenum = event.pagenum;
  const skipNum = pagesize * (pagenum - 1);
  return await db
    .collection('goods')
    .where({
      cat_id: event.cid,
    })
    .orderBy('add_time', 'desc')
    .limit(pagesize)
    .skip(skipNum)
    .get();
};
